﻿using System;

namespace FlickrXplorer.Web.Plugin.Exceptions
{
    /// <summary>
    /// Thrown when an error occurs while trying to execute the
    /// plugin.
    /// </summary>
    /// <value>
    /// This error will wrap the actual exception that occurred while
    /// executing the plugin. Inspect the <b>InnerException</b>
    /// property to find it.
    /// </value>                                                     
    public class PluginExecutionException : FlickrXplorerPluginException
    {
        /// <summary>
        /// Creates a new <see cref="FlickrXplorer.Web.Plugin.PluginExecutionException" text="ExecuteFlickrXplorerPluginException" />
        /// instance.
        /// </summary>
        /// <param name="plugin">The plugin in which the error
        ///                      occurred.</param>
        /// <param name="innerException">The actual exception that
        ///                              occurred.</param>                                                                                      
        public PluginExecutionException(FlickrXplorerPlugin plugin, Exception innerException)
            : base(plugin, GetMessage(plugin, innerException), innerException)
        {
        }

        private static string GetMessage(FlickrXplorerPlugin plugin, Exception innerException)
        {
            return String.Format("An exception of type '{0}' was caught while executing the plugin '{1}'",
                                 innerException.GetType().Name ?? "(no name)",
                                 plugin.Name);
        }
    }
}